package com.qf.lanzhou.blog.api.controller.notification;

import com.qf.lanzhou.blog.api.controller.BaseServletPost;
import com.qf.lanzhou.blog.api.service.NotificationService;
import com.qf.lanzhou.blog.api.service.impl.NotificationServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 是柠檬甜
 * @ClassName NotificationChangeStatusServlet
 * @description 通知状态修改类
 * @date 2020/12/16 15:53
 * @modifier 是柠檬甜
 * @date 2020-12-16 15:53
 * @Version V1.0
 */
@WebServlet("/changeStatus.do")
public class NotificationChangeStatusServlet extends BaseServletPost {
    private NotificationService notificationService=new NotificationServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        //获取参数
        String id1 = req.getParameter("id1");
        String id2 = req.getParameter("id2");
        //将参数转换为Long类型
        long longId1 = Long.parseLong(id1);
        long longId2 = Long.parseLong(id2);
        try{
            notificationService.change(longId1,longId2);
            successResultWrite("发布成功",resp);
        }catch (RuntimeException e){
            String message = e.getMessage();
            failedResultWrite(message,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
